home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / printer / indentln.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  3.7 KB  |  139 lines

  1. ;void  indentln(strg,margin);
  2. ;  char  *strg;
  3. ;  unsigned short  margin;
  4.  
  5.     EXTRN  _memory_model:byte
  6.     EXTRN  _error_code:byte
  7.     EXTRN  _time_out:byte
  8.  
  9. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  10.     ASSUME  CS:_TEXT
  11.     PUBLIC  _indentln
  12. _indentln proc near
  13.     push bp            ;
  14.     mov  bp,sp        ;set stack frame
  15.     push di            ;
  16.     push si            ;
  17.     cmp  _memory_model,0    ;near or far?
  18.     jle  begin        ;jump if near
  19.     inc  bp            ;else add 2 to BP
  20.     inc  bp            ;
  21. begin:    push ds            ;save DS
  22.     mov  ah,1        ;BIOS func to init prtr
  23.     mov  dx,0        ;choose LPT1
  24.     int  17h        ;initialize the prtr port
  25.     mov  di,[bp+6]        ;margin value to DI
  26.     sub  ax,ax        ;AX = 0
  27.     mov  es,ax        ;ES = 0
  28.     mov  dx,es:[408H]    ;get LPT1 base address
  29.     sub  bx,bx        ;0 = no error
  30.     mov  _error_code,1    ;1 = printer error
  31.     mov  al,_time_out    ;get _time_out seconds
  32.     cmp  _memory_model,2    ;data near or far?
  33.     jb   A1            ;jump if near
  34.     lds  si,dword ptr[bp+4] ;DS:SI pts to Strg
  35.     inc  bp            ;add 2 to BP since dword ptr
  36.     inc  bp            ;
  37.     jmp  short A2        ;
  38. A1:    mov  si,[bp+4]        ;near case
  39. A2:    or   al,al        ;don't allow zero seconds
  40.     jnz  A3            ;
  41.     mov  al,3        ;default to 3 seconds
  42. A3:    mov  cl,18        ;18 ticks per second
  43.     mul  cl            ;
  44.     mov  [bp+6],ax        ;save count
  45.     sub  cx,cx        ;clear CX
  46.     push si            ;count string length...
  47. A4:    cmp  byte ptr [si],0    ;end of string?
  48.     je   A5            ;jump if so
  49.     inc  si            ;forward string ptr
  50.     inc  cx            ;inc length counter
  51.     jmp  short A4        ;loop
  52. A5:    pop  si            ;restore ptr to start of string
  53.     jcxz L4            ;CR/LF if null string
  54.     or   di,di        ;test for 0-length margin
  55.     jz   L2            ;jump ahead if zero
  56. L1:    mov  al,32        ;set space char in AL
  57.     call Writeit        ;
  58.     or   ah,ah        ;
  59.     jz   L6            ;
  60.     dec  di            ;else dec margin counter
  61.     jnz  L1            ;
  62. L2:    mov  al,[si]        ;mov character to AL
  63.     inc  si            ;forward ptr for next time
  64. L3:    call Writeit        ;
  65.     or   ah,ah        ;
  66.     jz   L6            ;
  67.     loop L2            ;go write next char
  68. L4:    inc  cx            ;will reenter loop
  69.     cmp  bh,2        ;BH = 0 first time around
  70.     je   L6            ;when 2, quit routine
  71.     inc  bh            ;inc BH before looping
  72.     cmp  bh,2        ;second time?
  73.     jne  L5            ;jump ahead if not
  74.     mov  al,13        ;ready carriage return
  75.     call Writeit        ;
  76.     or   ah,ah        ;
  77.     jz   L6            ;
  78. L5:    mov  al,10        ;ready line feed
  79.     call Writeit        ;
  80.     or   ah,ah        ;
  81.     jz   L6            ;
  82.     pop  ds            ;
  83.     mov  _error_code,0    ;0 = no error
  84.     jmp  short L7        ;
  85. L6:     pop  ds            ;
  86. L7:    pop  si            ;
  87.     pop  di            ;
  88.     pop  bp            ;
  89.     cmp  _memory_model,0    ;quit
  90.     jle  quit        ;
  91.     db   0CBh        ;RET far
  92. quit:    ret            ;RET near
  93. Writeit    PROC
  94.     out  dx,al        ;send to output data register
  95.     inc  dx            ;forward to status register
  96.     push cx            ;save string counter
  97.     call GetBiosCount    ;get timer reading
  98.     mov  bx,cx        ;make copy
  99.     add  cx,[bp+6]        ;add delay count
  100.     cmp  bx,cx        ;if timer doesn't turn over...
  101.     jb   L8            ;go ahead
  102.     mov  cx,[bp+6]        ;otherwise, extend delay
  103. L8:    mov  [bp+4],cx        ;save target count on stack
  104. Wait:    in   al,dx        ;get status value
  105.     test al,8        ;test for printer error
  106.     jz   Error        ;
  107.     test al,80h        ;test for Printer Ready
  108.     jnz  Ready        ;jump if ready
  109. Error:    call GetBiosCount    ;
  110.     cmp  cx,[bp+4]        ;compare to target
  111.     jb   Wait        ;    
  112.     pop  cx            ;restore string counter
  113.     mov  ah,0        ;return code for failure
  114.     jmp  short L9        ;return
  115. Ready:    pop  cx            ;restore string counter
  116.     inc  dx            ; output control register
  117.     mov  al,13        ;bits for strobe signal
  118.     out  dx,al        ;send the signal
  119.     dec  al            ;change to strobe OFF
  120.     out  dx,al        ;send the signal
  121.     dec  dx            ;point back to
  122.     dec  dx            ;  base address
  123.     mov  ah,1        ;return code for success
  124. L9:    ret              ;
  125. Writeit    endp
  126. GetBIOSCount PROC
  127.     push dx            ;return value in CX:DX
  128.     push ax            ;
  129.     sub  ah,ah        ;function number
  130.     int  1ah        ;get timer count
  131.     mov  cx,dx        ;low word in CX
  132.     pop  ax            ;
  133.     pop  dx
  134.     ret
  135. GetBIOSCount endp
  136. _indentln endp
  137. _TEXT    ENDS
  138.     END
  139.